<?php

namespace app\console\command;

use app\common\model\Vod;
use Aws\AwsService;
use CloudFlare\CloudFlareApiClient;
use HuaweiVod\HuaweiVod;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;
use think\Log;

class ListCloudflareVod extends Command
{
    protected function configure()
    {
        $this->setName('list_cloudflare_vod')
            ->setDescription('vod list');
    }

    protected function execute(Input $input, Output $output)
    {
        $output->info("execute list cloudflare videos");
        try {
//            $this->getVideoList($output);
            $this->getVideoStorage($output);
        } catch (\Exception $exception) {
            Log::error($exception->getMessage());
            Log::error($exception->getTraceAsString());
//            $output->error($exception->getMessage());
        }
    }

    protected function getVideoList($output)
    {
        $cfClient = new CloudFlareApiClient();
        for ($i = 0; $i < 24; $i++) {
            $start = '2024-07-19T' . sprintf("%02d", $i) . ':00:00Z';
            $end = '2024-07-19T' . sprintf("%02d", $i) . ':59:59Z';
            $output->info('begin to get video list:' . $start . ' to ' . $end);
            $result = $cfClient->getVideoList($start, $end);
            Log::info(json_encode($result));
        }
    }

    protected function getVideoStorage($output)
    {
        $cfClient = new CloudFlareApiClient();
        $result = $cfClient->getStorageUseage();
        if ($result) {
            if (is_string($result)) {
                $result = json_decode($result, true);
            }
            $output->info('storage result:' . json_encode($result));
        }
    }
}
